using LogSystem;
using UnityEngine;
using Yoozoo.Gameplay.RTS;

namespace Yoozoo.Gameplay.City
{
    public class CityRealAiRoleControllerBase
    {
        /// <summary>
        /// Uid 计数器
        /// </summary>
        private static int ROLE_UID_INDEX = 0;
        
        /// <summary>
        /// 小人唯一ID
        /// </summary>
        public int Uid { get; }
        
        /// <summary>
        /// 出生房间Id
        /// </summary>
        public int BirthContainerId { get; }

        protected CityRealAiContainerManagerBase _containerMgr;

        protected CityRealAiConfigManager _cfgMgr;
        
        /// <summary>
        /// ai 实体表现
        /// </summary>
        protected GameObject _roleObj;

#if UNITY_EDITOR
        /// <summary>
        /// 调试物体
        /// </summary>
        protected GameObject _debugObj;
#endif

        /// <summary>
        /// GPU Skinning
        /// </summary>
        protected ModelInstaning model;

        public CityRealAiRoleControllerBase(int birthContainerId)
        {
            var uid = ROLE_UID_INDEX++;
            if (ROLE_UID_INDEX == int.MaxValue)
            {
                ROLE_UID_INDEX = 0;
                Debug.LogWarning(LogModule.CityAI, "生成过的小人数量已达 int类型 最大值，重置Uid计数器");
            }

            Uid = uid;
            BirthContainerId = birthContainerId;
            _cfgMgr = CityRealAiManager.GetInstance().ConfigMgr;
        }

        public CityRealAiContainerManagerBase GetContainerMgr()
        {
            return _containerMgr;
        }

        public virtual void UpdateContainer(CityRealAiContainerManagerBase containerMgr)
        {
            _containerMgr = containerMgr;
        }

        public virtual void OnUpdate()
        {
            
        }

        public virtual void Dispose()
        {
        }

        public GameObject GetRoleObj()
        {
            return _roleObj;
        }
    }
}